package com.zp.self.module.eventBus.config;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;

/**
 * @author ：by peng.zeng
 * @date ：Created 2022/1/13 11:32
 * @description ：
 */
@Configuration
public class EventBusConfig {

    final EventListener eventListener;

    @Autowired
    public EventBusConfig(EventListener eventListener) {
        this.eventListener = eventListener;
    }

    @Bean
    public EventBus eventBus(){
        EventBus eventBus = new EventBus();
        eventBus.register(eventListener);
        return eventBus;
    }

    @Bean
    public AsyncEventBus asyncEventBus() {
        AsyncEventBus asyncEventBus = new AsyncEventBus("asyncDefault", Executors.newFixedThreadPool(2));
        asyncEventBus.register(eventListener);
        return asyncEventBus;
    }

}
